package com.example.blog.service;

import com.example.blog.mapper.BlogMapper;
import com.example.blog.mapper.UserInfoMapper;
import com.example.blog.model.BlogInfo;
import com.example.blog.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * ClassName: UserService
 * Package: IntelliJ IDEA
 * Description:
 *
 * @Author 谷京京
 * @Create 2024/3/26 23:03
 * @Version 1.0
 */
@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlogMapper blogMapper;

    public UserInfo queryByName(String username) {
        return userInfoMapper.queryByName(username);
    }

    public UserInfo queryById(Integer userId) {
        return userInfoMapper.queryById(userId);
    }

    public UserInfo getAuthorInfo(Integer blogId) {
        //1. 根据博客Id获取userId
        BlogInfo blogInfo = blogMapper.queryById(blogId);
        if (blogInfo == null || blogInfo.getUserId() < 0) {
            return null;
        }
        return userInfoMapper.queryById(blogInfo.getUserId());
    }
}
